import router from '../router'
function getUserInfo(){
  let userInfo=window.localStorage.getItem("userInfo");
  // if(userInfo.userNum && userInfo.pass){
  if(userInfo){
    return true;
  }else{
    return false;
  }
}


var routerFlag = false
router.beforeEach(async (to, from, next) => {
  if (to.path === '/login') {
    next()
    return

  } else {
    if (getUserInfo()) {
      next()
      /*if (!routerFlag) {
        next({ ...to, replace: true })
        routerFlag = true
      }*/
    } else {
      next('/login')
      routerFlag = false
    }
  }
})
